package com.example.coffeejava.Service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.coffeejava.Dto.CountDto;
import com.example.coffeejava.Dto.Result;
import com.example.coffeejava.Entity.Admin;
import com.example.coffeejava.Entity.Info;
import com.example.coffeejava.Entity.UserHolder;
import com.example.coffeejava.Mapper.AdminMapper;
import com.example.coffeejava.Mapper.OrderMapper;
import com.example.coffeejava.Service.AdminService;
import com.example.coffeejava.Service.InfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
    @Resource
    private OrderMapper orderMapper;
    @Resource
    private InfoService infoService;
    public Result getcount() {
        Map<String, Integer> map = new HashMap<>();
        Integer curtotalprice = orderMapper.getcurcount1(UserHolder.getUser().getId());
        Integer curtotalCount = orderMapper.getcurtcount1(UserHolder.getUser().getId());
        Integer alltotalprice = orderMapper.gettotalprice1(UserHolder.getUser().getId());
        Integer alltotalCount = orderMapper.gettotalcount1(UserHolder.getUser().getId());
        map.put("curtotalprice", curtotalprice);
        map.put("curtotalCount", curtotalCount);
        map.put("alltotalprice", alltotalprice);
        map.put("alltotalCount", alltotalCount);
        System.out.println(map);
        return Result.ok(map);
    }
    public   Result chart(){
        return Result.ok(orderMapper.getprice1());
    }
    public     Result chart2(){
        List<CountDto> list=new ArrayList<>();
        List<Info> list1=infoService.list();
        for (Info info:list1) {
            CountDto countDto = new CountDto();
            countDto.setName(info.getName());
            Integer ids = Math.toIntExact(info.getId());

            countDto.setCount(orderMapper.getcount3(ids));
            list.add(countDto);
        }
        return Result.ok(list);
    }
}
